$(document).ready(function() {

	// 主菜单下拉效果
	var mainMenu = $('#main-menu');
	var allMenuLi = $('#main-menu li');
	var mainMenuLi = $('#main-menu>li');
	for (let i = 0; i < allMenuLi.length; i++) {
		$(allMenuLi[i]).children('a').on('click', function() {
			$('#main-menu li.current').toggleClass('current');
			$(allMenuLi[i]).toggleClass('current');
		});
	}

	for (let i = 0; i < mainMenuLi.length; i++) {
		$(mainMenuLi[i]).children('a').on('click', function() {
			$('#main-menu>li.active').toggleClass('active');
			$(mainMenuLi[i]).toggleClass('active');
		});
	}


	// 放缩界面
	var view_box = $('.view-box');
	var view_btn = $('.hd-changeview');
	view_btn.on('click', function() {
		view_box.toggleClass('stretch-view');
	});

	// 用户菜单效果
	var hd_user = $('.hd-user');
	var user_menu = $('.user-menu');
	var timer1;
	hd_user.hover(function() {
		clearTimeout(timer1);
		user_menu.css({
			'display': 'block'
		});
	}, function() {
		timer1 = setTimeout(function() {
			user_menu.css({
				'display': 'none'
			})
		}, 200);
	});

	// 显示用户名
	var userArr = JSON.parse(localStorage.getItem('userArr'));
	var curr_user = JSON.parse(localStorage.getItem('curr_user'));
	var user_name = $('.hd-user .name');
	user_name.text(userArr[`${curr_user}`]['username']);

	// 用户退出
	var login_out = $('#login-out');
	login_out.on('click', function() {
		userArr[`${curr_user}`]['logined'] = false;
		curr_user = {};
		localStorage.setItem('userArr', JSON.stringify(userArr));
		localStorage.setItem('curr_user', JSON.stringify(curr_user));
		window.location.href = 'pages/login.html';
	});
	
	// 浏览器关闭页面注销用户
	window.onunload = function(event) {
		userArr[`${curr_user}`]['logined'] = false;
		curr_user = {};
		localStorage.setItem('userArr', JSON.stringify(userArr));
		localStorage.setItem('curr_user', JSON.stringify(curr_user));
	}

});
